import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            char[] c = str.toCharArray();
            boolean[][] dp = new boolean[c.length][c.length];
            int[][] count = new int[c.length][c.length];
            // dp[i][j]表示[i,j]之间的字符串是否是回文串
            // count[i][j]表示[i,j]之间最长回文子字符串的长度
            int maxLength = -1;
            for (int i = 0; i < c.length; i++) {
                for (int j = i; j >= 0; j--) {
                    if (j+1 >= i) {
                        dp[j][i] = (c[i] == c[j]);
                    } else {
                        dp[j][i] = (c[i] == c[j] && dp[j+1][i-1]);
                    }
                    if (j+1 > i-1) {
                        count[j][i] = c[j] == c[i] ? 0 : 2;
                    } else {
                        count[j][i] = dp[j][i] ? count[j+1][i-1] : count[j+1][i-1] + 2;
                    }
                    maxLength = Math.max(maxLength, count[j][i]);
                }
            }
            System.out.println(maxLength);
        }
    }
}
